﻿using Dino;
using NUnit.Framework;
using Rhino.Mocks;

namespace Tests.Dino.UnitOfWorkTests
{
    public partial class UnitOfWorkTests
    {
        [TestFixture]
        public class WhenCommittingASession
        {
            private UnitOfWork _session;
            private IObjectContext _context1;
            private IObjectContext _context2;

            [SetUp]
            public void Setup()
            {
                _context1 = MockRepository.GenerateMock<IObjectContext>();
                _context2 = MockRepository.GenerateMock<IObjectContext>();

                _session = UnitOfWork.Configure(c =>
                    {
                        c.WithContext<TestContext>(() => _context1);
                        c.WithContext<TestContext2>(() => _context2);
                    }).Initialize();

                _session.GetContext<TestContext>();
                _session.GetContext<TestContext2>();
            }

            [TearDown]
            public void Teardown()
            {
                _context1.VerifyAllExpectations();
                _context2.VerifyAllExpectations();
            }

            [Test]
            public void ItCallsCommitOnAllContexts()
            {
                _context1.Expect(c => c.Commit());
                _context2.Expect(c => c.Commit());

                _session.Commit();
            }
        }
    }


}
